package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.Orders;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrdersMapper {
    /**
     *新建订单
     * @param orders
     * @return
     */
    @Insert("insert into orders(userId,businessId,orderDate,orderTotal,daId,orderState) values(#{userId},#{businessId},#{orderDate},#{orderTotal},#{daId},0)")
    @Options(useGeneratedKeys = true,keyProperty = "orderId",keyColumn = "orderId")
    public int saveOrders(Orders orders)throws Exception;

    /**
     *根据orderId查询订单
     * @param orderId
     * @return
     */
    public Orders getOrdersById(Integer orderId)throws Exception;

    /**
     *根据userId查询订单
     * @param userId
     * @return
     */
    public List<Orders> listOrdersByUserId(String userId)throws Exception;

    /**
     *更新订单
     * @param orderId
     * @return
     */
    @Update("update orders set orderState=1 where orderId=#{orderId}")
    public int updateorderState(Integer orderId)throws Exception;
}
